package org.dromara.common.core.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.*;

public class UuidUtil {

	public static String get32UUID() {
		String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return uuid;
	}
	public static void main(String[] args) {
//		System.out.println(get32UUID());


		String ss = "[{\"opr_id\":\"1053ed6554684b09a703deb0be440c98\",\"resolve_time\":\"2022-09-01 13:39:38\",\"status\":\"SUCCESS\",\"data\":[{\"type\":22,\"value\":[\"0.00\"],\"dsp\":\" 购电次数: 0   剩余金额: 0.00 元  总用电量: 20.00 kWh \"}]}]";

		List<Map<String, Object>> responseContent= new ArrayList<>();
		JSONArray contentArray = JSONUtil.parseArray(ss);
		for(int i = 0; i < contentArray.size(); ++i) {
			Map<String, Object> contentMap = new HashMap<>();
			JSONObject contentObject = contentArray.getJSONObject(i);
			Set<String> keySet = contentObject.keySet();
			for(String key: keySet) {
				contentMap.put(key, contentObject.getObj(key, Object.class));
			}
			responseContent.add(contentMap);
		}

		if(CollUtil.isNotEmpty(responseContent)) {
			for (Map<String, Object> map : responseContent) {

				JSONObject jsonObject = new JSONObject();
				JSONArray data = map.containsKey("data") ? JSONUtil.parseArray(map.get("data").toString()) : null;
				if(data !=null && data.size() > 0){
					jsonObject = (JSONObject)data.get(0);
				}

				String value = jsonObject.getJSONArray("value").get(0).toString();

				//剩余账户余额
//		double value = jsonObject.containsKey("value") ? Double.parseDouble() : 0d;
				System.out.println("剩余账户余额: " + value);
			}
		}




	}
}

